Insert raw commands into .smt2 file with #![raw_command()] attribute#21
Conversation
|
Probably I have to add some more tests and documentation comments. |
| @@ -0,0 +1,20 @@ | |||
| //@error-in-other-file: UnexpectedToken | |||
There was a problem hiding this comment.
How can I test that the Thrust panics with a specific error message? I tried using //@error-in-other-file, but I might be misunderstanding its purpose.
There was a problem hiding this comment.
I think testing panic messages is not possible with the current testing framework (ui_test https://docs.rs/ui_test/). However, I don't think we want tests for panicking cases anyway; it would be beneficial if we supported reporting rustc diagnostics for parse errors, but it's out of scope for now.
There was a problem hiding this comment.
I've added the description about this situation as comments for now:
// This test panics with "invalid attribute" for now.
// TODO: reporting rustc diagnostics for parse errors| let ts = analyze::annot::extract_annot_tokens(attrs.clone()); | ||
| let parser = annot::AnnotParser::new( | ||
| // TODO: this resolver is not actually used. | ||
| analyze::annot::ParamResolver::default() |
There was a problem hiding this comment.
parseg_raw_definition() is implemented on annot::AnnotParser and it's new() requires any Resolver instance, which isn't actually used in parsing of raw definitions.
I might have to fix so that no Resolver is required for this analysis.
There was a problem hiding this comment.
I don't think it needs to be implemented in AnnotParser. How about extracting the string from the annotation in a method within crate_::Analyzer?
| let ts = analyze::annot::extract_annot_tokens(attrs.clone()); | ||
| let parser = annot::AnnotParser::new( | ||
| // TODO: this resolver is not actually used. | ||
| analyze::annot::ParamResolver::default() |
There was a problem hiding this comment.
I don't think it needs to be implemented in AnnotParser. How about extracting the string from the annotation in a method within crate_::Analyzer?
| @@ -0,0 +1,20 @@ | |||
| //@error-in-other-file: UnexpectedToken | |||
There was a problem hiding this comment.
I think testing panic messages is not possible with the current testing framework (ui_test https://docs.rs/ui_test/). However, I don't think we want tests for panicking cases anyway; it would be beneficial if we supported reporting rustc diagnostics for parse errors, but it's out of scope for now.
| //@check-pass | ||
| //@compile-flags: -Adead_code -C debug-assertions=off | ||
|
|
||
| // Insert definitions written in SMT-LIB2 format into .smt file directly. |
There was a problem hiding this comment.
nit
| // Insert definitions written in SMT-LIB2 format into .smt file directly. | |
| // Insert definitions written in SMT-LIB2 format into .smt2 file directly. |
There was a problem hiding this comment.
To avoid using the AnnotParser and Parser, we need to move parse_annot_raw_definition() out of annot::Parser. However, doing so means it will lose access to the various parsing utilities and error definitions defined there.
Do you have any suggestions on how to handle this?
There was a problem hiding this comment.
(maybe this #21 (comment))
Do you have any suggestions on how to handle this?
parse_annot_raw_definition just extracts a string literal from the TokenStream and not much else (so I'd rather call it "extract" than "parse"), so I think you can simply write that extraction directly in crate_::Analyzer without using utilities from AnnotParser. For errors, you can just panic! for now. I haven't tested it, but I think code like the following should work.
let raw_command = ts.iter().find_map(|tt| match tt {
TokenTree::Token(Token { kind: TokenKind::Literal(lit), .. }, _)
if lit.kind == LitKind::Str => Some(lit.symbol.to_string()),
_ => None,
}).expect("invalid raw_command annotation");|
|
||
| #[thrust::requires(true)] | ||
| #[thrust::ensures(result == 2 * x)] | ||
| // #[thrust::ensures(is_double(x, result))] |
There was a problem hiding this comment.
If you plan to uncomment this in a future PR, please add a note about it in the comments.
There was a problem hiding this comment.
I forgot to delete them, but I have deleted them now.
| for (p, def) in self.inner.pred_vars.iter_enumerated() { | ||
| if !def.debug_info.is_empty() { | ||
| writeln!(f, "{}", def.debug_info.display("; "))?; | ||
| for (p, cmd) in self.inner.pred_vars.iter_enumerated() { | ||
| if !cmd.debug_info.is_empty() { | ||
| writeln!(f, "{}", cmd.debug_info.display("; "))?; | ||
| } | ||
| writeln!( | ||
| f, | ||
| "(declare-fun {} {} Bool)\n", | ||
| p, | ||
| List::closed(def.sig.iter().map(|s| self.ctx.fmt_sort(s))) | ||
| List::closed(cmd.sig.iter().map(|s| self.ctx.fmt_sort(s))) |
There was a problem hiding this comment.
This seems to be an unrelated change.
55993e8 to
1434597
Compare
…s TokenTrees directly
Co-authored-by: Hiromi Ogawa <me@coord-e.com>
Co-authored-by: Hiromi Ogawa <me@coord-e.com>
This attribute allows users to inject arbitrary string literals directly into the generated .smt2 files using crate-level inner attributes.
By adding an inner attribute to the crate root, such as:
The attached string literal will be inserted into the head of the generated SMT-LIB2 file:
This feature is intended for debugging and testing. It enables the manual injection of SMT-LIB logic, serving as a workaround until a dedicated parser is implemented.